package com.game.net;

public abstract class Session<T, M> implements ConnectListener {
    protected String sessionId;

    protected Connect<M> connect;

    protected NetAddress address;

    protected Object reference;

    protected SessionListener sessionListener;

    public Session(String sessionId, Connect<M> connect, NetAddress address) {
        this.sessionId = sessionId;
        this.connect = connect;
        this.address = address;
    }

    public abstract void send(T paramT);

    public void close() {
        if (this.connect != null && this.connect.isActive())
            this.connect.close();
    }

    public void onConnectClose(Connect connect) {
        if (this.sessionListener != null)
            this.sessionListener.onSessionClose(this);
    }

    public String sessionId() {
        return this.sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public Connect getConnect() {
        return this.connect;
    }

    public void setConnect(Connect<M> connect) {
        this.connect = connect;
    }

    public NetAddress getAddress() {
        return this.address;
    }

    public void setAddress(NetAddress address) {
        this.address = address;
    }

    public Object getReference() {
        return this.reference;
    }

    public void setReference(Object reference) {
        this.reference = reference;
    }

    public SessionListener getSessionListener() {
        return this.sessionListener;
    }

    public void setSessionListener(SessionListener sessionListener) {
        this.sessionListener = sessionListener;
    }

    public String toString() {
        return "Session{sessionId=" + this.sessionId + ", connect=" + this.connect + ", address=" + this.address + ",hash" + hashCode() + '}';
    }
}
